"""
Viewer module for epistasis analysis UI
"""

import wx
import grid_epistasis_pages
import GUIconfig
import os
from gene_snp_checklist import GeneSnpChecklist 
import wx.lib.agw.customtreectrl as ctc


class EpistasisListbook(wx.Listbook):
    """
    A wx listbook containing four pages
    """

    def __init__(self, parent):
        wx.Listbook.__init__(self, parent, wx.ID_ANY, style=wx.BK_DEFAULT )#| wx.SUNKEN_BORDER )

        genotype_icon = wx.Bitmap(os.path.join(GUIconfig.images_directory,"DNA_icon.jpg"))
        phenotype_icon = wx.Bitmap(os.path.join(GUIconfig.images_directory,"blackmouse_icon.jpg"))
        class_icon = wx.Bitmap(os.path.join(GUIconfig.images_directory,"piechart_3d_icon6070_3.jpeg"))
        start_icon = wx.Bitmap(os.path.join(GUIconfig.images_directory,"gene_network_icon.png"))
        icons = [genotype_icon, phenotype_icon, class_icon, start_icon]
        
        il = wx.ImageList(70,70)
        for icon in icons:
            icon.SetSize(wx.Size(70,70))
            il.Add(icon)
        self.AssignImageList(il)
        
        self.genotypes_page = grid_epistasis_pages.select_genotypes_page(self)
        self.phenotypes_page = grid_epistasis_pages.select_phenotypes_page(self)
        self.classes_page = grid_epistasis_pages.select_classes_page(self)
        self.start_page = grid_epistasis_pages.start_analysis_page(self)
        
        pages = [(self.genotypes_page, "Select Genotypes"),
                 (self.phenotypes_page, "Select Phenotypes"),
                 (self.classes_page, "Select Classes"),
                 (self.start_page, "Start Epistasis Analysis")]
        
        
        imID = 0
        for page, label in pages:
            self.AddPage(page, label, imageId=imID)
            imID += 1

class GridEpistasisView(wx.Panel):
    """
    The main epistasis analysis viewer panel
    """

    def __init__(self, parent, size=(800,600)):
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size, wx.TAB_TRAVERSAL )

        self.epistasis_listbook = EpistasisListbook(self)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        sizer.Add(self.epistasis_listbook, 1, wx.ALL|wx.EXPAND, 5)
        

        # Bind events
        self.epistasis_listbook.genotypes_page.check_all.Bind( wx.EVT_BUTTON, self.OnGenotypesCheckall )
        self.epistasis_listbook.genotypes_page.uncheck_all.Bind( wx.EVT_BUTTON, self.OnGenotypesUncheckall )
        self.epistasis_listbook.genotypes_page.genotypes_filter.Bind( wx.EVT_TEXT, self.OnGenotypesFilterText )
        self.epistasis_listbook.genotypes_page.gene_snp_checklist.Bind( wx.EVT_TREE_ITEM_EXPANDING, self.OnGeneExpanding )
        self.epistasis_listbook.genotypes_page.gene_snp_checklist.Bind( ctc.EVT_TREE_ITEM_CHECKED, self.OnGenotypeClicked )
        self.epistasis_listbook.genotypes_page.lookup_genes.Bind( wx.EVT_BUTTON, self.OnStartGeneFinder )
       
        self.epistasis_listbook.phenotypes_page.check_all.Bind( wx.EVT_BUTTON, self.OnPhenotypesCheckall )
        self.epistasis_listbook.phenotypes_page.uncheck_all.Bind( wx.EVT_BUTTON, self.OnPhenotypesUncheckall )
        self.epistasis_listbook.phenotypes_page.phenotypes_filter.Bind( wx.EVT_TEXT, self.OnPhenotypesFilterText )
        self.epistasis_listbook.phenotypes_page.phenotypes_checklist.Bind( wx.EVT_CHECKLISTBOX, self.OnPhenotypeClicked )
        
        self.epistasis_listbook.classes_page.check_all.Bind( wx.EVT_BUTTON, self.OnClassesCheckall )
        self.epistasis_listbook.classes_page.uncheck_all.Bind( wx.EVT_BUTTON, self.OnClassesUncheckall )
        self.epistasis_listbook.classes_page.classes_checklist.Bind( wx.EVT_CHECKLISTBOX, self.OnClassClicked )
        self.epistasis_listbook.classes_page.selection_variable_list.Bind( wx.EVT_LISTBOX, self.OnSelectionVariable )
        
        self.epistasis_listbook.start_page.overview_button.Bind( wx.EVT_BUTTON, self.OnFullOverview )
        self.epistasis_listbook.start_page.start_analysis_button.Bind( wx.EVT_BUTTON, self.OnStartAnalysis )
        self.epistasis_listbook.start_page.cancel_button.Bind( wx.EVT_BUTTON, self.OnCancel )
        
        self.epistasis_listbook.Bind(wx.EVT_LISTBOOK_PAGE_CHANGED, self.OnPageChanged)
        self.epistasis_listbook.Bind(wx.EVT_LISTBOOK_PAGE_CHANGING, self.OnPageChanging)



    def OnPageChanged(self, event):
        event.Skip()

    def OnPageChanging(self, event):
        event.Skip()

    def OnGenotypesFilterText( self, event ):
        event.Skip()
       
    def OnGenotypeClicked(self, event):
        event.Skip()
        
    def OnStartGeneFinder(self, event):
        event.Skip()
    
    def OnGenotypesCheckall( self, event ):
        event.Skip()
    
    def OnGenotypesUncheckall( self, event ):
        event.Skip()
    
    def OnGeneExpanding(self, event):
        event.Skip()
            
    def OnPhenotypeClicked(self, event):
        event.Skip()        
        
    def OnPhenotypesFilterText( self, event ):
        event.Skip()

    def OnPhenotypesCheckall( self, event ):
        event.Skip()
    
    def OnPhenotypesUncheckall( self, event ):
        event.Skip()
    
    def OnClassClicked(self, event):
        event.Skip()        
    
    def OnclassesFilterText( self, event ):
        event.Skip()

    def OnClassesCheckall( self, event ):
        event.Skip()

    def OnClassesUncheckall( self, event ):
        event.Skip()

    def OnCancel( self, event ):
        event.Skip()
    
    def OnStartAnalysis( self, event ):
        event.Skip()

    def OnSelectionVariable(self, event):
        event.Skip()
    
    def OnFullOverview(self, event):
        event.Skip()
        
if __name__ == "__main__":
    app = wx.App(False)
    frame = wx.Frame(None, wx.ID_ANY, "Hello World", size=(1000,800)) # A Frame is a top-level window.
    win = GridEpistasisView(parent=frame)
    frame.Show()
    app.MainLoop()
